package com.gao.handler;

import com.alibaba.fastjson.JSON;
import com.gao.util.ResultVO;
import com.gao.util.WebUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author gao
 * @time 2022/11/05 11:42:47
 */
@Component
public class JsonAccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        String json = WebUtils.generateFailureJson("对不起，您未通过授权，无权访问该资源");
        WebUtils.renderString(response, json);
    }
}